package com.dlc.apk.core

import com.dlc.apk.util.LogPlus
import com.dlc.hardwareprotocol.serialport.command.recv.RecvBA
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers


class HardwareControllerImpl : IHardwareController {
    override fun startShipment(flowNo: Int, params: Map<String, Any>, executeCallback: IExecuteCallback?) {
        val cargoNumberType = params["cargoNumberType"] as Int
        val actionCargoRowNumberOrNo1 = params["actionCargoRowNumberOrNo1"] as Int
        DeviceSerialManager.instance.deviceMainSerialManager!!.sendA8(flowNo, cargoNumberType, actionCargoRowNumberOrNo1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(object : Observer<RecvBA> {
            override fun onSubscribe(d: Disposable) {
            }

            override fun onNext(t: RecvBA) {
                LogPlus.e("###指令应答成功->$t")
                executeCallback?.onResponseSuccess(true)
            }

            override fun onError(e: Throwable) {
                LogPlus.e("###指令应答失败,异常->${LogPlus.getStackTraceInfo(e)}")
                executeCallback?.onResponseFailed(e.message)
            }

            override fun onComplete() {
            }
        })
    }
}